<?php /* Smarty version 2.6.20, created on 2013-05-25 07:04:35
         compiled from _core/_include/module/_mvc/control/handlesearchparcel.tpl */ ?>
function HandleSearchParcel(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  this._popupBox = new PopupBox();

  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : function() {};
  
  this._query = (options && options.query) ? options.query : '1=1';
  
  this._search ={
           cfrom: null,
           cto: null,
           psend: true,
           preceived: true
         };
          
  this._createElements();
}

HandleSearchParcel.prototype._createElements = function() {
  var _self = this;
  this._gui.cfrom.value = (_self._search.cfrom) ? SimpleDate.format(_self._search.cfrom) : '';
  this._gui.cfrom.onclick = function() { var context = this;
                                                _self._changeDate.call(_self, this, _self._search.cfrom, function(sd) { _self._search.cfrom = sd; context.focus(); }, false);
                                                return false;
                                              };
  /*this._gui.cfrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                    if (code == 13) {
                                                     // _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.cfrom) ? JSON.stringify(_self._search.cfrom) : null, (_self._search.cfrom) ? JSON.stringify(_self._search.cfrom) : null, (_self._search.cfrom) ? JSON.stringify(_self._search.cfrom) : null, DOMUtils.findPos(this));
                                                    }
                                                  };*/
  this._gui.cto.value = (this._search.cto) ? SimpleDate.format(this._search.cto) : '';
  this._gui.cto.onclick = function() { var context = this;
                                              _self._changeDate.call(_self, this, _self._search.cto, function(sd) { _self._search.cto = sd; context.focus(); }, false);
                                              return false;
                                            };
  /*this._gui.cto.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                  if (code == 13) {
                                                   // _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.cfrom) ? JSON.stringify(_self._search.cfrom) : null, (_self._search.cfrom) ? JSON.stringify(_self._search.cfrom) : null, (_self._search.cfrom) ? JSON.stringify(_self._search.cfrom) : null, DOMUtils.findPos(this));
                                                  }
                                                };  */
  
  /*this._gui.mailNo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                              if (code == 13) {
                                                _self._callbackFunc(escape(((_self._gui.mailNo.value != '') ? 'd.name LIKE \'%' + _self._gui.mailNo.value + '%\'' : '1=1') + ' AND ' + ((_self._gui.customerNo.value != '') ? 'd.destination like \'%' + _self._gui.customerNo.value + '%\'' : '1 = 1')));
                                              }
                                            };*/
  this._gui.mailNo.onkeyup = function() { if (_self._gui.mailNo.value.length == 0) {
                                              _self._popupBox._close();
                                            } else {
                                              var div = document.createElement('div');
                                              var pos1 = DOMUtils.findPos(_self._gui.mailNo);
                                              var pos = [pos1[0], pos1[1] + 82];
                                              var query = "SELECT DISTINCT d.name FROM ns_parcels as d WHERE " + _self._query + "AND " + '((d.name LIKE \'%' + _self._gui.mailNo.value + '%\'))' + " ";
                                              MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                              new DialogSearchResult(div, _self._gui.mailNo, { query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._createElements(); }, php: Constant.FACTORY + '/customphp/mysqlcustom.php', width: 110 });
                                            }
                                          };
  /*this._gui.customerNo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                  if (code == 13) {
                                                    _self._callbackFunc(escape(((_self._gui.mailNo.value != '') ? 'd.name LIKE \'%' + _self._gui.mailNo.value + '%\'' : '1=1') + ' AND ' + ((_self._gui.customerNo.value != '') ? 'd.destination = \'' + _self._gui.customerNo.value + '\'' : '1 = 1')));
                                                  }
                                                };*/
  this._gui.customerNo.onkeyup = function() { if (_self._gui.customerNo.value.length == 0) {
                                                  _self._popupBox._close();
                                                } else {
                                                  var div = document.createElement('div');
                                                  var pos1 = DOMUtils.findPos(_self._gui.customerNo);
                                                  var pos = [pos1[0] + 1, pos1[1] + 82];
                                                  var query = "SELECT DISTINCT d.destination  FROM ns_parcels as d WHERE " + _self._query + " AND " + '((d.destination LIKE \'%' + _self._gui.customerNo.value + '%\'))' + " ";
                                                  MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                                  new DialogSearchResult(div, _self._gui.customerNo, { query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._createElements();}, php: Constant.FACTORY + '/customphp/mysqlcustom.php', width: 110});
                                                }
                                              };                                             
  
  this._gui.psend.defaultChecked = this._search.psend;
  this._gui.psend.onclick = function() { 
                                       /*_self._search.psend = this.checked;
                                       _self._callbackFunc(escape(((_self._gui.mailNo.value != '') ? 'd.name LIKE \'%' + _self._gui.mailNo.value + '%\'' : '1=1') + 
                                       ' AND ' + ((_self._gui.customerNo.value != '') ? 'd.destination = \'' + _self._gui.customerNo.value + '\'' : '1 = 1') + 
                                       ' AND ' + ((_self._gui.cfrom.value != '') ? 'd.createdDate >= \'' + SimpleDate.toStamp(_self._search.cfrom) + '\'' : '1 = 1') + 
                                       ' AND ' + ((_self._search.psend.checked == true) ? 'd.statues = \'s\'' : '1 = 1' + ' OR' + (_self._search.preceived.checked == true) ? 'd.statues = \'r\'' : '1 = 1')
                                       ));*/
                                       
                                           if(_self._search.psend==true)
                                           {
                                              _self._search.psend==true;
                                           }else{
                                              _self._search.psend==false;
                                           }                                      
                                       
                                          };                                                

  this._gui.preceived.defaultChecked = this._search.preceived;
  this._gui.preceived.onclick = function() { 
                                       //_self._search.preceived = this.checked;
                                       /*_self._callbackFunc(escape(((_self._gui.mailNo.value != '') ? 'd.name LIKE \'%' + _self._gui.mailNo.value + '%\'' : '1=1') + 
                                       ' AND ' + ((_self._gui.customerNo.value != '') ? 'd.destination = \'' + _self._gui.customerNo.value + '\'' : '1 = 1') + 
                                       ' AND ' + ((_self._gui.cfrom.value != '') ? 'd.createdDate >= \'' + SimpleDate.toStamp(_self._search.cfrom) + '\'' : '1 = 1') + 
                                       ' AND ' + ((_self._search.psend.checked == true) ? 'd.statues = \'s\'' : '1 = 1' + ' OR' + (_self._search.preceived.checked == true) ? 'd.statues = \'r\'' : '1 = 1') 
                                       ));*/
                                           if(_self._search.preceived==true)
                                           {
                                              _self._search.preceived==true;
                                           }else{
                                              _self._search.preceived==false;
                                           }
                                          };     

  this._gui.button.onclick = function() {_self._callbackFunc(encodeURIComponent(((_self._gui.mailNo.value != '') ? 'd.name LIKE \'%' + _self._gui.mailNo.value + '%\'' : '1=1') + 
                                       ' AND ' + ((_self._gui.customerNo.value != '') ? 'd.destination like \'%' + _self._gui.customerNo.value + '%\'' : '1 = 1')+ 
                                       ' AND ' + ((_self._gui.cfrom.value != '') ? 'd.createdDate >= \'' + SimpleDate.toStamp(_self._search.cfrom) + '\'' : '1 = 1') + 
                                       ' AND ' + ((_self._gui.cto.value != '') ? 'd.createdDate <= \'' + SimpleDate.toStamp(_self._search.cto) + '\'' : '1 = 1') + 
                                       ' AND ' + ( ((_self._gui.psend.checked == true && _self._gui.preceived.checked == false) ? 'd.statues = \'s\'' : '1 = 1') + ' and ' + ((_self._gui.psend.checked == false && _self._gui.preceived.checked == true) ? 'd.statues = \'r\'' : '1 = 1') 
                                             )
                                       )); };
};

HandleSearchParcel.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandleSearchParcel.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandleSearchParcel.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};